package com.attendance.security.info.service;

import com.alibaba.fastjson.JSONObject;
import com.attendance.security.info.mapper.LoginInfoMapper;
import com.attendance.security.info.pojo.LoginInfo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 登录信息服务
 *
 * @author 今朝
 * @date 2021/03/18
 */
@Service
public class LoginInfoService {
    @Autowired
    LoginInfoMapper loginInfoMapper;

    public void addLoginInfo(LoginInfo loginInfo) {
        loginInfoMapper.insert(loginInfo);
    }

    public Page<LoginInfo> getListPage(Integer pageNum, Integer limit, String searchParams) {
        JSONObject parse = JSONObject.parseObject(searchParams);
        QueryWrapper<LoginInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByDesc("id");
        for (String key : parse.keySet()) {
            queryWrapper.like(key, parse.get(key));
        }
        Page<LoginInfo> page = new Page<>(pageNum, limit);
        loginInfoMapper.selectPage(page, queryWrapper);
        return page;
    }

    public Page<LoginInfo> getListPage(Integer pageNum, Integer limit) {
        QueryWrapper<LoginInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByDesc("id");
        Page<LoginInfo> page = new Page<>(pageNum, limit);
        loginInfoMapper.selectPage(page, queryWrapper);
        return page;
    }
}
